﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Member_MemberInformation : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
            {//获取用户身份的代码
                string EncrTicket = Request.Cookies[FormsAuthentication.FormsCookieName].Value;
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(EncrTicket);
                string UserName = ticket.Name;
                //将用户的信息显示在下面的文本框中
                Members member = new Members();
                foreach (var m in member.GetMembersByName(UserName))
                {
                    TB_username.Text = m.userName;
                    TB_age.Text = Convert.ToString(m.age);
                    TB_post.Text = m.postcode;
                    TB_tel.Text = m.tel;
                    TB_question.Text = m.question;
                    TB_answer.Text = m.answer;
                    TB_email.Text = m.email;
                    TB_address.Text = m.adress;
                    DL_sex.SelectedIndex = DL_sex.Items.IndexOf(DL_sex.Items.FindByText(m.sex)); 

                }

            }
            else 
            {
                Response.Redirect("~/Default.aspx");
            }

        }
    }

    //提交修改后的用户信息
    protected void Button1_Click(object sender, EventArgs e)
    {
        string EncrTicket = Request.Cookies[FormsAuthentication.FormsCookieName].Value;
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(EncrTicket);
        string UserName = ticket.Name;
        Members member = new Members();
        string password;
        int id;
        
        foreach (var m in member.GetMembersByName(UserName))
        {
            if (Session["password"] != null)
                password = Convert.ToString(Session["password"]);
            else

                password = m.passWord;
            id = m.userId;
            member.assertMembers(TB_username.Text, DL_sex.SelectedItem.Text, Convert.ToInt32(TB_age.Text),
                                password, TB_question.Text, TB_answer.Text, TB_address.Text, TB_post.Text,
                                TB_tel.Text, TB_email.Text, DateTime.Now);

            member.removeMem(id);
        }

    }
}